package com.tony.second.controller;

import com.tony.second.bean.ConfigBean;
import com.tony.second.bean.CeShiConfigBean;
import com.tony.second.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * create by xuxia on 2024/1/26 08:57
 */
@RestController
public class IndexController {

    /**
     * 注入UserBean
     */
    @Autowired
    private UserBean userBean;

    /**
     * 注入ConfigBean
     */
    @Autowired
    private ConfigBean configBean;

    /**
     * 注入TestConfigBean
     */
    @Autowired
    private CeShiConfigBean ceShiConfigBean;

    /**
     * 测试通过在bean中属性定义中使用@Value(name="${user.xm}")的方式读取配置文件中相应的属性值
     *
     * @return
     */
    @RequestMapping(value = "/")
    public String index() {
        return userBean.getName() + "已经" + userBean.getAge() + "岁了";
    }

    /**
     * 测试通过注解@ConfigurationProperties的方式读取全局配置文件中的属性值
     *
     * @return
     */
    @RequestMapping(value = "/config")
    public String configProperties() {
        return configBean.getName() + "的价格为：" + configBean.getPrice();
    }

    /**
     * 测试读取自定义配置文件里配置的属性值
     *
     * @return
     */
    @RequestMapping(value = "/customConfiguration")
    public String customConfiguration() {
        return ceShiConfigBean.getName() + "的年龄为：" + ceShiConfigBean.getAge() + "岁";
    }

}
